// pages/content/content.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        bookContent: {},
        contentId: "",
        collectionId: "",
        title:""
    },
    /**
     * 读取API
     */
    getApi() {
        var app = getApp();
        var api = "https://" + app.globalData.env + "." + app.globalData.region + ".kits.tcloudbase.com/cms/" + app.globalData.kitId + "/v1/open-api/projects/" + app.globalData.projectId + "/collections/" + this.data.collectionId + "/contents/" + this.data.contentId;
        return api;
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.setData({
            contentId: options.id,
            collectionId: options.bookid
        });
        this.getTitle();
        this.getBookContent();
    },
    /**
     * 生成title
     */
    getTitle() {
        switch (this.data.collectionId) {
            case "ttg":
                this.setData({
                    title: "汤头歌诀"
                });
                break;
            case "zyg":
                this.setData({
                    title: "中药歌诀"
                });
                break;
            case "zyxwg":
                this.setData({
                    title: "中医穴位歌诀"
                });
                break;
        }
    },
    /**
     * 读取中医歌诀列表
     */
    getBookContent() {
        let that = this;
        wx.request({
            url: that.getApi(),
            header: {
                'content-type': 'application/json'
            },
            success(res) {
                console.log(res);
                that.setData({
                    bookContent: res.data.result
                });
            }
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})